﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SqlMonitoring.Agent.AgentServiceBase;
using System.Management;
using Microsoft.Win32;


namespace SqlMonitoring.Agent
{
    public class Windows2003 : AgentSkeleton
    {

        public override int SleepTime()
        {
            return 180; //seconds
        }

        /// <summary>
        /// Use to get recuring data ( state of a service )
        /// </summary>
        public override void ExecuteInternal()
        {
            Log.Debug("Checking for running services");
            
            ManagementObjectSearcher queryServices =
                new ManagementObjectSearcher("SELECT DisplayName, State FROM Win32_Service");

            foreach (ManagementObject mo in queryServices.Get())
            {
                Log.Info(string.Format("\"{0}\" appears to be in a {1} state.", mo["DisplayName"].ToString(), mo["State"].ToString()));
            }

            Log.Debug("Checking done...");
        }

        ManagementObjectSearcher oldServices;
        /// <summary>
        /// Use to configure things, to get onetime things ( memory size ed )
        /// </summary>
        public override void ConfigureInternal()
        {
            ManagementObjectSearcher queryServices =
                new ManagementObjectSearcher("SELECT DisplayName, State FROM Win32_Service");

            foreach (ManagementObject mo in queryServices.Get())
            {
                Log.Info(string.Format("Found service \"{0}\".", mo["DisplayName"].ToString()));
            }
            IsConfigured = true;
        }
    }
}
